<?php
/**
 * Created by PhpStorm.
 * User: change
 * Date: 2016/12/23
 * Time: 20:19
 * 医院
 */

namespace Admin\Model;
use Base\Model\BaseModel;
class HospitalinfoModel extends BaseModel
{
    protected $_validate = array(
        array('name', 'require', '名称必须填写'),
        array('name', '', '医院已存在', 0, 'unique', 3),
//        array('officephone', '', '手机号已存在', 2),
        array('name', '', '手机号已存在', 0, 'unique', 2),
     //   array('officephone', 'phone', '手机号格式不正确,如果是固定电话，必须形如(xxxx-xxxxxxx)',2),
//        array('name','/^[a-zA-Z_\x{4e00}-\x{9fa5}]+$/u', '医院名称不符合规则！',3),
        array('linkman','/^[a-zA-Z_\x{4e00}-\x{9fa5}]+$/u', '联系人名称不符合规则！',2),
    );
    protected $_auto = array(
        array('status', '0'),
        array('createTime','mydate','1','callback'),
        array('lastEditTime','mydate','3','callback'),
    );
    protected function mydate(){
        return date("Y-m-d H:i:s");
    }
//    protected  function phone($phone){
//        if(!strlen($phone)==11){
//            return false;
//        }
//    }

    protected $_link=array(
        //省市
        'province' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'provinceid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //市县
        'city' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'cityid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        ),
        //县区
        'region' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'regionid',
            'parent_key' => 'id',
            'mapping_fields' => 'aerainfo_id,aerainfo_name'
        )
    );
 }